package com.example.demo.controller;

 
import java.util.Map;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.entity.mime.content.StringBody;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.auth0.jwt.JWT;
import com.example.demo.common.ErrorUtils; 
import com.example.demo.constants.ResultEnity;
import com.example.demo.constants.pojo.UserInfo;
import com.example.demo.entity.BookEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;

//@Controller
@RestController
@Api(tags = "订书相关接口文档")
@Log4j2
public class BookController extends BaseController {
	
	@SuppressWarnings("deprecation")
	@RequestMapping("/book/list")
	//@ResponseBody
	@ApiOperation( httpMethod = "POST", value = "订书操作", notes = "用户订书操作")
	public ResultEnity<BookEntity> List(@RequestBody UserInfo user) throws UnsupportedEncodingException {
	    String result;
		
	    BookEntity book=new BookEntity();
		book.setName(user.getUserName() + "的<<asfsdfsdf>>书");	
		
		List<Map<String,Object>> resultMap=new ArrayList<Map<String,Object>>(); 

		Map<String,Object> bookMap= new HashMap<String, Object>();
		bookMap.put("1", book);
		
		resultMap.add(bookMap);
		result= JSON.toJSONString(book).toString();
		
		UserInfo userInfo=new UserInfo();
		userInfo.setUserId("1");
		userInfo.setUserName("wxdong");
		userInfo.setPassword("asdfasdfsadf");
		userInfo.setRolesDescription("管理员");

		//result = "hello word !!";		
	    return ResultEnity.Success("成功", book);
	}
	
	@RequestMapping("/book/add")	
	//@ResponseBody
	//@RequestParam(value="name")	 
	@ApiOperation( httpMethod = "POST", value = "添加", notes = "添加", hidden= true)
	public String Add(@ApiParam(name = "name", value = "名称",required = true) @RequestParam(value="name") String name) {

		try {
			int n=0;
			int z=233/n;		
		}
		catch (Exception e) {
			// TODO: handle exception
			log.error("程序出错了,错误信息:"+e.getMessage()+"堆栈信息："+ErrorUtils.getStackTrace(e));
		}
		
		return ""+name+" ok";
	}
	
	@RequestMapping("/book/query")	
	@ApiOperation(httpMethod = "POST",  value = "图书查询", notes = "图书查询")
	public String Query(@ApiParam(name = "data", value = "数据",required = true) @RequestBody String data) throws UnsupportedEncodingException {
		String result= java.net.URLDecoder.decode(data, "UTF-8");		
		return ""+result+" ok";
	}	
	
	@RequestMapping("/book/query2")	 
	@ApiOperation(httpMethod = "POST",  value = "高级查询", notes = "高级查询" , hidden = true )
	public String Query2(String data) throws UnsupportedEncodingException {
		String result= java.net.URLDecoder.decode(data, "UTF-8");		
		return ""+result+" ok";
	}
	
	@RequestMapping("/book/Query3")	 
	@ApiOperation(httpMethod = "POST",  value = "高级查询", notes = "高级查询")
	public ResultEnity<BookEntity> Query3(@RequestBody BookEntity data) throws UnsupportedEncodingException {
		String result= java.net.URLDecoder.decode("afsdfasd", "UTF-8");		
		return ResultEnity.Success("asfasdfsa", data);
	}

}
